import { createRouter, createWebHistory } from 'vue-router'

import Layout from '@/layout/index.vue'
import Cart from '@/views/cart/index.vue'
import Category from '@/views/category/index.vue'
import Checkout from '@/views/checkout/index.vue'
import Detail from '@/views/detail/index.vue'
import Home from '@/views/home/index.vue'
import Login from '@/views/login/index.vue'
import PayResult from '@/views/pay-result/index.vue'
import Pay from '@/views/pay/index.vue'
import SubCategory from '@/views/sub-category/index.vue'
import UserCenter from '@/views/user-center/index.vue'
import UcInfo from '@/views/user-center/uc-info/index.vue'
import UcOrder from '@/views/user-center/uc-order/index.vue'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // path和component对应关系的位置
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          path: '',
          component: Home
        },
        {
          path: 'category/:id',
          component: Category
        },
        {
          path: 'category/sub/:id',
          name: 'subCategory',
          component: SubCategory
        },
        {
          path: 'detail/:id',
          component: Detail
        },
        {
          path: 'cart',
          component: Cart
        },
        {
          path: 'checkout',
          component: Checkout
        },
        {
          path: 'pay',
          component: Pay
        },
        {
          path: 'pay-result',
          component: PayResult
        },
        {
          path: 'user-center',
          component: UserCenter,
          redirect: '/user-center/uc-info',
          children: [
            {
              path: 'uc-info',
              component: UcInfo
            },
            {
              path: 'uc-order',
              component: UcOrder
            }
          ]
        }
      ]
    },
    {
      path: '/login',
      component: Login
    },
  ],
  // 路由滚动行为定制，也就是说在路由切换时，页面滚动到顶部
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router


